var seletevipLevelName = $('#vipLevelNameValue').val();
if (seletevipLevelName != "") {
    $("#vipLevelName option[value='" + seletevipLevelName + "']").attr("selected", "selected");
}

$(".TransactionBox").click(function () {
    $(this).addClass("butStyle").siblings().removeClass('butStyle');
    if ($(this).html() == "充积分") {
        $("#cz").show();
        $("#tk").hide();
        $("#zz").hide();
        $("#transferdiv").hide();
        $("#customerName").hide();
        $("#mode").val("充值");
    } else if ($(this).html() == "退积分") {
        $("#cz").hide();
        $("#tk").show();
        $("#zz").hide();
        $("#transferdiv").hide();
        $("#customerName").hide();
        $("#mode").val("退积分");
    } else if ($(this).html() == "转积分") {
        $("#cz").hide();
        $("#tk").hide();
        $("#zz").show();
        $("#transferdiv").show();
        $("#customerName").show();
        $("#mode").val("转积分");
    }
});

function getJfbalance() {
    var recharge = parseFloat($("#recharge").val());
    var vipLevelName = parseFloat($("#vipLevelName").val());
    if ($("#mode").val() == "充值") {
        if (isNaN(recharge) != true) {
            $("#getJfbalance").val((recharge * vipLevelName).toFixed(0));
        } else {
            $("#getJfbalance").val(0)
        }
    }
}

//提交
function submission() {
    var money;
    if ($("#mode").val() == "充值") {
        money = document.getElementById("getJfbalance").value;
    } else if ($("#mode").val() == "退积分") {
        money = "-" + (document.getElementById("retreat").value);
        var moneys = document.getElementById("moneys").innerHTML; //当前余额
        if (parseFloat($("#retreat").val()) > parseFloat(moneys)) {
            alert('退积分不能大于当前积分！');
            return;
        }
    }else if($("#mode").val() == "转积分"){
        money = document.getElementById("transfer").value;
        var moneys = document.getElementById("moneys").innerHTML; //当前余额
        if (parseFloat($("#transfer").val()) > parseFloat(moneys)) {
            alert('转账积分不能大于当前余额！');
            return;
        }
        var reservationsId = $("input[name='about']:checked").val();
        if( reservationsId==null || reservationsId =='' ){
            alert('请选择转入人！');
            return;
        }
    }
    var remarks = document.getElementById("remarks").value;
    var customerId = document.getElementById("customerId").value;
    var mode = $("#mode").val();
    if (money == null || money == '' || money == '-') {
        alert('请输入积分！');
        return;
    }
    if (money.length > 6) {
        alert('不能大于六位,请重新输入！');
        return;
    }
    $.ajax({
        url: Feng.ctxPath + "/customer/addCustomerScore",
        type: "post",
        data: {
            "jfbalance": money,
            "customerId": customerId,
            "mode": mode,
            "remarks": remarks,
            "reservationsId": reservationsId
        },
        success: function (data) {
            Feng.success('操作成功!');
            window.parent.location.href = Feng.ctxPath + '/customerDetails/to_openBileLists/' + customerId + "/6";
            $("#cancel").click();
        },
        error: function (data) {
            alert('没有权限，请联系系统管理员!');
            $("#cancel").click();
        }
    });
}


$("#search").click(function () { //查询转积分患者
    $.ajax({
        url: Feng.ctxPath + "/customer/getRefereeScore",
        type: "post",
        data: {
            "name":$("#name").val()
        },
        success: function (data) {
            var listr ="";
            for(var i=0;i<data.length;i++){ //把数据渲染到archiving_content容器里面
                listr += '<div style="width: 25%;flex: none;"><span class="checkboxStyle">' +
                    '<input class="checkboxClass" type="radio" value="'+data[i].reservationsId+'" name="about" ' +
                    'id="click_'+data[i].account+'"></span>' +
                    '<label for="click_'+data[i].account+'"  class="labelStyle"">'+data[i].account+'</label></div>';
            }
            document.getElementById('customerName').innerHTML = listr;  // 初始化科室下拉框
        },
        error: function (data) {
            alert('没有权限，请联系系统管理员!');
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        }
    });
});

$("#customerName").on('click', '.checkboxStyle', function () {
    $(this).addClass('selection').parent().siblings().children('.checkboxStyle').removeClass('selection');
});